home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c++ / 1067 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  2.0 KB

  1. Path: engnews1.Eng.Sun.COM!taumet!clamage
  2. From: "Nathan Myers <ncm@cantrip.org>" <ncm@cantrip.org>
  3. Newsgroups: comp.std.c++
  4. Subject: Re: auto_ptr::is_owner()
  5. Date: 13 Apr 1996 23:17:16 GMT
  6. Organization: Best Internet Communications
  7. Approved: clamage@eng.sun.com (comp.std.c++)
  8. Message-ID: <316F533D.262C89BD@cantrip.org>
  9. References: <009A0A5CE1159CC0.49802F14@ittpub.nl> <gregorDpoGM2.Hw2@netcom.com>
  10. NNTP-Posting-Host: taumet.eng.sun.com
  11. Mime-Version: 1.0
  12. Content-Type: text/plain; charset=us-ascii
  13. Content-Transfer-Encoding: 7bit
  14. X-Nntp-Posting-Host: ncm.vip.best.com
  15. X-Mailer: Mozilla 2.01 (X11; I; Linux 1.2.13 i386)
  16. Content-Length: 1022
  17. Originator: clamage@taumet
  18.  
  19. Greg Colvin wrote:
  20.  
  21. > In article <009A0A5CE1159CC0.49802F14@ittpub.nl> "Wil Evers" <wil@ittpub.nl>:
  22. > >What I definitely do not understand is why the new auto_ptr template
  23. > >doesn't even allow us to query if it is actually owning the object
  24. > >pointed to.
  25.  
  26. > I found it very hard to contrive examples where is_owner() would
  27. > actually be useful. 
  28.  
  29. I agree with Greg here: any code that is intended to execute 
  30. differently, depending on the value returned by putative member 
  31. auto_ptr<>::is_owner(), is just bad code.
  32.  
  33. I can imagine:
  34.  
  35.   auto_ptr<T> p1;
  36.   auto_ptr<T> p2 = new T;
  37.   if (...) {
  38.      p1 = p2;
  39.   }
  40.   // what to do here?   
  41.  
  42. The answer is: it's your responsibility to keep track of ownership
  43. of pointers; if you can't do it manually, then automate it with 
  44. reference counting or something.  That's not what auto_ptr<> is for;
  45. its purpose is to make sure that the value "new T" gets destroyed.  
  46. It does that job perfectly; don't ask it to do your job too.
  47.  
  48. Nathan Myers
  49. ncm@cantrip.org  http://www.cantrip.org/
  50.  
  51.  
  52. [ comp.std.c++ is moderated.  To submit articles: try just posting with      ]
  53. [ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu         ]
  54. [ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
  55. [ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
  56. [ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]
  57.